package com.tbsoft.ehr.dao;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;

import org.hibernate.Session;

import com.tbsoft.ehr.model.AttachFile;
import com.tbsoft.ehr.model.BaseEntity;

/**
 * @desc 基础Dao
 * @author vastdream
 *
 */
public interface BaseDao<T extends BaseEntity> {
	
	/**
     * 
     * Insert a new entity. create- and lastmodified-date is set with current
     * time.
     * 
     * @see Session#save(Object)
     * 
     * @param entity
     *            - detached entity object
     */
    public T save(T entity);

    /**
     * 
     * Inserts a new detached entity or updates if it already exists. create-
     * and update-date are set automatically.
     * 
     * @see Session#saveOrUpdate(Object)
     * 
     * @param entity
     *            - entity object to be inserted or updated
     */
    public T saveOrUpdate(T entity);

    /**
     * 
     * Deletes entity from persistence store.
     * 
     * @see Session#delete(Object)
     * 
     * @param entity
     */
    public void delete(T entity);

    /**
     * 
     * Copy the state of the given object onto the persistent object with the
     * same identifier. If there is no persistent instance currently associated
     * with the session, it will be loaded.
     * 
     * @see Session#merge(Object)
     * 
     * @param entity
     * @return
     */
    public T merge(T entity);

    /**
     * 保存对象列表
     * 
     * @param items
     * @return
     * @throws Exception
     */
    public boolean saveList(List<T> items);

    /**
     * 保存对象列表
     * 
     * @param items
     * @return
     * @throws Exception
     */
    public boolean saveOrUpdateList(List<T> items);
    /**
     * @desc 逻辑删除
     * @param entityClass
     * @param id
     */
    public void logicDelete(Class<? extends BaseEntity> entityClass,Serializable id );
    /**
     * @desc 保存附件
     * @param attachFileList
     * @param businessId
     */
    public void saveOrUpdateAttachfile(List<AttachFile> attachFileList,String businessId) throws IOException;
	
}
